<form class="form-inline" method="get">

    <div class="form-group col-xs-2"  style="width: 20%;">
        <div class="col-xs-12">
            <input class="form-control" name="id" value="{$id}"
                   placeholder="商品ID">
        </div>
    </div>
   
    <div class="form-group col-xs-2"  style="width: 20%;">
        <div class="col-xs-12">
            <input class="form-control" name="title" value="{$title}"
                   placeholder="奖名称|商品名称">
        </div>
    </div>

    <div class="form-group col-xs-2">
        <select id="type-selector" name="type" class="form-control" tabindex="-1">
            <option value="">
                无选择
            </option>
            {foreach $typeList as $item}
            <option value="{$item.type}" {if $type==$item['type']}selected{/if} >{$item.type_name}</option>
            {/foreach}
        </select>
    </div>

    <div class="form-group col-xs-2">
        <select id="visible-selector" name="is_visible" class="form-control" tabindex="-1">
            <option value="">
                无选择
            </option>
            <option value="1" {if condition="$is_visible != '' && $is_visible==1"}selected{/if} >显示</option>
            <option value="0" {if condition="$is_visible != '' && $is_visible==0"}selected{/if} >隐藏</option>
        </select>
    </div>


    <div class="form-group col-xs-2">
        <button type="submit" class="btn btn-success">
            搜索
        </button>

        <button type="button" class="btn btn-primary" onclick="modal('{:url(\'add\')}','添加奖品','60%','90%')">
            添加奖品
        </button>
    </div>
</form>

<hr>
<p style="color: red;">每次抽奖 系统将查询 条件为 【显示】 且 【库存大于0】 的商品 求比重和，当前商品的比重 除以 比重和 即为中奖概率</p>
<p style="color: red;">当前 【显示】 且 【库存大于0】 的商品的比重和：<font color="black">{$gl}</font> </p>
<p style="color: red;">假如比重和为100，某商品比重为1，抽中此商品的概率为1/100</p>
<p style="color: red;">（商品隐藏、比重为0、库存为0 将无法被抽中）</p>
<p style="color: red;">宠物奖励以推广收益的形式到账</p>
<table class="table table-bordered table-striped">
    <thead>
    <tr>
        <td>ID</td>
        <td>奖名称</td>
        <td>商品名称</td>
        <td>缩略图</td>
        <td>商品类型</td>
        <td>是否显示</td>
        <td>商品数值</td>
        <td>商品比重</td>
        <td>概率</td>
        <td>库存</td>
        <td>创建时间<br>更新时间</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
    {volist name="list" id="item"}
    <tr>

        <td>{$item.id}</td>
        <td>{$item.title}</td>
        <td>{$item.goods_title}</td>
        <td>
            <a href="javascript:void(0);" onclick="ejectImg('{$item.img_url}','商品{$item.title}logo');">
                <img style="width: 100px;" src="{$item.img_url}" />
            </a>
        </td>
        <td>{$item.type|get_lottery_type}</td>
        <td>
            {if $item["is_visible"]}
            <label class="label label-success" data-toggle="ajaxSwitch" data-switch-status="1"
                   data-switch-value-0="1|显示|label label-success|{:url('visible',array('id'=>$item['id'],'status'=>1))}"
                   data-switch-value-1="0|隐藏|label label-danger|{:url('visible',array('id'=>$item['id'],'status'=>0))}">显示</label>
            {else}
            <label class="label label-danger" data-toggle="ajaxSwitch" data-switch-status="0"
                   data-switch-value-0="1|显示|label label-success|{:url('visible',array('id'=>$item['id'],'status'=>1))}"
                   data-switch-value-1="0|隐藏|label label-danger|{:url('visible',array('id'=>$item['id'],'status'=>0))}">隐藏</label>
            {/if}
        </td>

        <td>{$item.num}</td>
        <td>{$item.gl}</td>
        <td style="word-break: break-all;color: red;font-weight: bold;">
            <?php
                if($gl<=0){
                    echo '总比重为0无法计算';
                }else{
                    if($item['stock']<=0){
                        echo 0;
                    }elseif($item['gl']<=0){
                        echo 0;
                    }else{
                        echo $item['gl'].'/'.$gl;
                    }
                }
            ?>
        </td>
        <td>{$item.stock}</td>

        <td>
            <p>{$item.create_time|show_datetime}</p>
            <p>{$item.update_time|show_datetime}</p>
        </td>
        <td>
            <div class="btn-group">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    操作
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                    <li>
                        <a href="javascript:void(0)" onclick="modal('{:url(\'edit\',array(\'id\'=>$item[\'id\']))}', '编辑商品','60%','90%')">
                            编辑
                        </a>
                    </li>
                    <li>
                        <a href="javascript:void(0)" data-toggle="confirm"
                           data-title="删除奖品"
                           data-content="确认删除奖品？删除后不可恢复，请谨慎操作！"
                           data-url="{:url('remove',array('id'=>$item['id']))}">
                            删除
                        </a>
                    </li>

                    <li role="separator" class="divider"></li>
                </ul>
            </div>
        </td>
    </tr>
    {/volist}
    </tbody>
</table>

<div class="row">
    <div style="text-align: right;">
        {$list->render()}
    </div>
</div>

<script src="__PUBLIC__/vendors/select2/js/select2.min.js"></script>
<script type="application/javascript">
    $(function () {


        $("#type-selector").select2({
            placeholder: "选择商品类型",
            allowClear: true
        });
        $("#visible-selector").select2({
            placeholder: "选择是否显示",
            allowClear: true
        });

    });

</script>